﻿using System;
using System.Web;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Collections.Generic;
using System.Net.Mime;
using System.Net;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace OARepository.Layouts.OARepository
{
    public partial class Browse : LayoutsPageBase
    {
        private RepoContext repoContext = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            string path = HttpContext.Current.Request.PathInfo;

            List<String> parts = new List<string>(path.Split('/'));
            parts.RemoveAt(0); // PathInfo starts with '/'

            if (parts.Count != 0)
                throw new HttpException((int)HttpStatusCode.NotFound, "Not Found");

            RepoContext = new RepoContext();

            Title = "Browse";
            PlaceHolderPageTitle.Text = Title;
            PlaceHolderPageTitleInTitleArea.Text = Title;
            ContentTitle.InnerText = Title;

            BulletedList ul = new BulletedList();
            ul.DisplayMode = BulletedListDisplayMode.HyperLink;

            foreach(SPList list in RepoContext.GetLists().Values)
            {
                ListItem li = new ListItem(list.Title, RepoContext.ListUrl(list));
                ul.Items.Add(li);
            }

            Content.Controls.Add(ul);
        }

        protected override bool AllowAnonymousAccess
        {
            get
            {
                return true;
            }
        }

        protected RepoContext RepoContext
        {
            get
            {
                return repoContext;
            }
            set
            {
                repoContext = value;
            }
        }

    }
}
